<template>
<van-nav-bar
    left-arrow
    @click-left="gotoleft"
    title="确认订单"
  />
<div class="confirm-order-container">
  <div class="reciver-info">
    <div class="left">
      <van-image :src="locationpng"></van-image>
    </div>
    <div class="right">
      <div class="basic-info">
        <text class="name">{{info.userName}}</text>
        <text class="phone">{{info.telNumber}}</text>
      </div>
      <div class="address">{{info.provinceName+info.cityName+info.countyName+info.detailInfo}}</div>
      <!-- <div class="tip">请注意接听送货电话</div> -->
    </div>
  </div>
  <div class="product-info">
    <div class="basic-info">
      <div class="img-box">
        <van-image class="goods-img" :src="goods.primaryPicUrl"></van-image>
      </div>
      <div class="right">
        <div class="name">{{goods.goodsName}}</div>
        <div class="counts">数量：1</div>
        <div class="time">发货时间：48小时内</div>
      </div>
    </div>
    <div class="divide-line"></div>
    <div class="other-info">
      <!-- <div class="delivery-type">
        <div class="text">
          <text>配送方式：</text>
          <text>普通配送</text>
        </div>
        <van-icon name="arrow" color="#737373"/>
      </div>
      <div class="cost">运费：<text class="money">￥0</text></div> -->
      <div class="comment">
        订单备注：<input type="text" v-model="comment" placeholder="需要协商的请留言" placeholder-class="placeholder" />
      </div>
    </div>
    <div class="points">共1件 小计：<text class="point-text">{{goods.retailPrice||goods.virtualPrice}}积分</text></div>
  </div>

  <div class="bottom">
    <text decode>共1件 &nbsp;&nbsp;</text>
    <text>合计：</text>
    <text class="total">{{goods.retailPrice||goods.virtualPrice}}积分</text>
    <div class="submit-btn" @click="submit">提交订单</div>
  </div>
</div>
</template>

<script>
import locationpng from '../assets/images/location.png'
import {
  GetGoodsDetail,
  SubmitOrder,
  GetDefault
} from '@/api'
import {reactive,toRefs} from 'vue'
import router from '../router'
import { Toast } from 'vant';
export default {
  name: 'confirmOrder',
  setup(props) {
    //参数
    let confirmOrder = reactive({
      active: 0,
      goods:null,
      goodsID:'',
      standard:'',
      locationpng,
      comment: '',
      info: null,
    })
    
    confirmOrder.goodsID = router.currentRoute.value.query.goodsID
    confirmOrder.standard = router.currentRoute.value.query.standard
    console.log('confirmOrder',confirmOrder,router)
    GetGoodsDetail({
      goodsId: confirmOrder.goodsID,
      specIds: confirmOrder.standard
    }).then(res => {
      console.log('get goods confirmOrder==>', res)
      if(res.code === 0){
          confirmOrder.goods=res.data
      }
    })
    GetDefault().then(res => {
      if (res.code === 0) {
          confirmOrder.info = res.data
      }
      console.log('get default address=>', res)
    })
    function submit() {
      // if(localStorage.getItem('token')){
      //   router.push('/home')
      // }else{
      //   Toast('请登录后操作！')
      //   router.push('/login')
      // }
      router.push('/orderSuccess')
    }
    function gotoleft(){
      router.go(-1)
    }
    //挂载
    return{ ...toRefs(confirmOrder),submit,gotoleft}
  }
}
</script>

<style scoped>
page{
  width:100%;
  height:100%;
}

.confirm-order-container{
  width:100%;
  height:100%;
  padding-bottom:calc(90px + env(safe-area-inset-top));
  box-sizing: border-box;
  background-color: #eeeeee;
}

.reciver-info{
  display: flex;
  width:90%;
  padding:20px 40px;
  margin:0 auto;
  box-sizing: border-box;
  border-bottom-left-radius: 15px;
  border-bottom-right-radius: 15px;
  background-color: #ffffff;
}

.reciver-info .left{
  width:50px;
  height: 50px;
}

.reciver-info .left image{
  display: block;
  width:100%;
  height: 100%;
}

.reciver-info .right{
  margin-left: 20px;
  font-size: 28px;
}

.reciver-info .name{
  font-size: 32px;
}

.reciver-info .phone{
  margin-left: 20px;
  color:#737373;
}

.reciver-info .address,
.reciver-info .tip{
  margin-top: 10px;
  color:#737373;
}

.product-info{
  width:90%;
  margin: 20px auto 0;
  padding:20px 50px;
  box-sizing: border-box;
  border-radius: 15px;
  background-color: #ffffff;
}

.product-info .basic-info{
  display: flex;
}

.product-info .basic-info .img-box{
  width:180px;
  height: 180px;
  border:1px solid #e6e6e6;
  border-radius: 15px;
  overflow: hidden;
}

.product-info .basic-info .goods-img{
  display: block;
  width:100%;
  height: 100%;
  object-fit: contain;
}

.product-info .basic-info .right{
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin-left: 20px;
}

.product-info .basic-info .name{
  font-weight: bold;
}

.product-info .basic-info .counts,
.product-info .basic-info .time{
  font-size: 28px;
  color:#737373;
}

.divide-line{
  width:95%;
  height: 2px;
  margin:20px auto;
  background-color: #e6e6e6;
}

.other-info .delivery-type{
  display: flex;
  justify-content: space-between;
}

.other-info .delivery-type text:nth-child(2){
  color:#737373;
}

.other-info .cost{
  margin:10px 0;
}

.other-info .cost .money{
  color:#737373;
}

.other-info .comment{
  display: flex;
}

.other-info .placeholder{
  font-size: 28px;
}

.points{
  text-align: right;
  margin-top: 30px;
}

.points .point-text{
  color:red;
}

.bottom{
  position: fixed;
  bottom:0;
  left:0;
  display: flex;
  align-items: center;
  width:100%;
  height:90px;
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: 20%;
  background-color: #ffffff;
}

.bottom .total{
  color:red;
}

.bottom .submit-btn{
  /* width:150px; */
  margin-left: 40px;
  padding:10px 20px;
  border-radius: 30px;
  text-align: center;
  color:#ffffff;
  background-color: #31b573;
}
</style>